package com.farm.farming.controller;

import com.farm.entity.PageResult;
import com.farm.entity.Result;
import com.farm.entity.StatusCode;
import com.farm.farming.pojo.Cust_User;
import com.farm.farming.service.Cust_UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/custUser")
@RestController
public class Cust_userController {

    @Autowired
    private Cust_UserService cust_userService;

    @GetMapping(value = "/findPage")
    public Result findPage(@RequestParam(value = "name",required = false,defaultValue = "")String name,
                           @RequestParam(value = "page",required = false,defaultValue = "0")Integer currentPage,
                           @RequestParam(value = "size",required = false,defaultValue = "10")Integer size){

        PageResult<Cust_User> page = null;
        try {
            page = cust_userService.findPage(name,currentPage,size);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,StatusCode.OK,"查询用户管理员失败");
        }

        return new Result(true, StatusCode.OK,"查询用户管理员完成",page);
    }

    @GetMapping("/updateById/{id}")
    public Result updateById(@PathVariable("id")Integer id){
        try {
            cust_userService.updateById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,StatusCode.ERROR,"修改密码失败");
        }

        return new Result(true,StatusCode.OK,"修改密码完成");
    }
}
